package communication;

/***
 * 
 * @author Bogusław Zaręba
 *
 */

public enum MessageType {
	ERROR,
	PLAYER_LOGIN,
	GAME_MASTER_LOGIN,
	LOGIN_RESPONSE,
	BEGIN_GAME,
	GAME_STATE,
	MOVE,
	THANK_YOU,
	LEAVE_GAME,
	PLAYER_LEFT_GAME,
	LOGOUT,
	SERVER_SHUTDOWN,
	CHAMPION_LIST;
	
	public String toString() {
		switch(this) {
			case ERROR:
				return "error";
			case PLAYER_LOGIN:
				return "playerLogin";
			case GAME_MASTER_LOGIN: 
				return "gameMasterLogin";
			case LOGIN_RESPONSE: 
				return "loginResponse";
			case BEGIN_GAME: 
				return "beginGame";
			case GAME_STATE: 
				return "gameState";
			case MOVE: 
				return "move";
			case THANK_YOU: 
				return "thank you";
			case LEAVE_GAME: 
				return "leaveGame"; 
			case PLAYER_LEFT_GAME: 
				return "playerLeftGame";
			case LOGOUT: 
				return "logout";
			case SERVER_SHUTDOWN: 
				return "serverShutdown";
			case CHAMPION_LIST: 
				return "championList";
		}
		return null;
	}
	
	public static MessageType parse(String str) {
		if(str.equalsIgnoreCase("error"))
			return ERROR;
		if(str.equalsIgnoreCase("playerLogin"))
			return PLAYER_LOGIN;
		if(str.equalsIgnoreCase("gameMasterLogin"))
			return GAME_MASTER_LOGIN;
		if(str.equalsIgnoreCase("loginResponse"))
			return LOGIN_RESPONSE;		
		if(str.equalsIgnoreCase("beginGame"))
			return BEGIN_GAME;
		if(str.equalsIgnoreCase("gameState"))
			return GAME_STATE;
		if(str.equalsIgnoreCase("move"))
			return MOVE;	
		if(str.equalsIgnoreCase("thank you"))
			return THANK_YOU;	
		if(str.equalsIgnoreCase("leaveGame"))
			return LEAVE_GAME;	
		if(str.equalsIgnoreCase("playerLeftGame"))
			return PLAYER_LEFT_GAME;	
		if(str.equalsIgnoreCase("logout"))
			return LOGOUT;
		if(str.equalsIgnoreCase("serverShutdown"))
			return SERVER_SHUTDOWN;	
		if(str.equalsIgnoreCase("championList"))
			return CHAMPION_LIST;
		return null;
	}
}
